package com.fafica.util;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;

import com.fafica.entidades.AlunoFafica;
import com.fafica.entidades.Artigo;
import com.fafica.entidades.GrupoTrabalho;
import com.fafica.entidades.Inscrito;
import com.fafica.entidades.Minicurso;
import com.fafica.entidades.InscritoMinicurso;



public class HibernateUtil {

	private static SessionFactory sessionFactory;

	static {
		Configuration configuration = new Configuration();
		
		configuration.addAnnotatedClass(InscritoMinicurso.class);
		configuration.addAnnotatedClass(Inscrito.class);
		configuration.addAnnotatedClass(AlunoFafica.class);
		configuration.addAnnotatedClass(Artigo.class);
		configuration.addAnnotatedClass(GrupoTrabalho.class);
		configuration.addAnnotatedClass(Minicurso.class);
		
		configuration.configure();
		ServiceRegistryBuilder serviceRegistryBuilder = new ServiceRegistryBuilder()
				.applySettings(configuration.getProperties());
		ServiceRegistry serviceRegistry = serviceRegistryBuilder
				.buildServiceRegistry();
		sessionFactory = configuration.buildSessionFactory(serviceRegistry);
	}

	public static Session getSession() {
		Session session = sessionFactory.openSession();
		return session;
	}

}